# -*- coding: utf8 -*-
from ned_app import NEd
from ned_app.nmj_access import setNMJInterface, getNMJInterface
from ned_app.nmj_proxy import NMJInterface
import logging
import ned_app.blueprints
import pkgutil
import sys



LOGGER = logging.getLogger(__name__)
if __name__ == "__main__":
	logging.basicConfig(level=logging.DEBUG)
	package = ned_app.blueprints
	try:
		conf = sys.argv[1]
	except IndexError:
		conf = "conf/ned.conf"	
		
	setNMJInterface(NMJInterface(conf))
	for importer, modname, ispkg in pkgutil.iter_modules(package.__path__):
		LOGGER.info("Found submodule %s (is a package: %s), importer=%s", modname, ispkg, importer)
		module = __import__("ned_app.blueprints.%s" % modname, fromlist=["get_blueprint"])
		NEd.register_blueprint(module.get_blueprint())
	NEd.run(host="0.0.0.0", port=5000)
	LOGGER.info("Main Application stopped")
	getNMJInterface().stop()

